#ifndef MEDIADATAPICKER_H
#define MEDIADATAPICKER_H

#include <QObject>
#include <QQmlParserStatus>
#include <QtMultimedia/QMediaPlayer>
#include <QDir>

class MediaDataPicker : public QObject, public QQmlParserStatus
{
    Q_OBJECT
    Q_PROPERTY(QObject* player READ player WRITE setPlayer NOTIFY playerChanged)
    Q_PROPERTY(QString title READ title NOTIFY titleChanged)
    Q_PROPERTY(QString artist READ artist NOTIFY artistChanged)
    Q_PROPERTY(QString albumTitle READ albumTitle NOTIFY albumTitleChanged)
    Q_PROPERTY(QString albumArtist READ albumArtist NOTIFY albumArtistChanged)
    Q_PROPERTY(QUrl coverArtUrl READ coverArtUrl NOTIFY coverArtUrlChanged)
    Q_PROPERTY(int trackNumber READ trackNumber NOTIFY trackNumberChanged)
public:
    explicit MediaDataPicker(QObject *parent = 0);

    QObject *player();
    void setPlayer(QObject *qmlMediaPlayer);

    QString title() const;
    QString artist() const;
    QString albumTitle() const;
    QString albumArtist() const;
    QUrl coverArtUrl() const;
    int trackNumber() const;

    // [0]
    virtual void classBegin() Q_DECL_OVERRIDE;
    virtual void componentComplete() Q_DECL_OVERRIDE;

public slots:
    void reset();

signals:
    void playerChanged();
    void titleChanged();
    void artistChanged();
    void albumTitleChanged();
    void albumArtistChanged();
    void coverArtUrlChanged();
    void trackNumberChanged();

private slots:
    void onMetaDataChanged(const QString &key, const QVariant &value);

private:
    QDir m_coverDir;
    bool m_componentComplete = false;
    QMediaPlayer *m_player = Q_NULLPTR;
    QUrl m_coverArtUrl;
};

#endif // MEDIADATAPICKER_H
